package com.enjoy.basic.serializable;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import org.msgpack.MessagePack;

import java.util.List;

/**
 * Created by HP on 2019/7/15.
 */
public class MsgPackDecoder extends MessageToMessageDecoder<ByteBuf> {
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        int length=byteBuf.readableBytes();
        byte[] array=new byte[length];
        byteBuf.getBytes(byteBuf.readerIndex(),array,0,length);
        MessagePack messagePack=new MessagePack();
        list.add(messagePack.read(array,User.class));
        //ReferenceCountUtil.release(byteBuf);//这里不需要释放了 因为父类已经实现了
    }
}
